-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include: devicetree: Add port and endpoint macros #80649
include: devicetree: Add port and endpoint macros #80649
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks typical to have both DT_XXX(inst)
and DT_INST_XXX(inst)
variants defined, but not sure if the non-INST_
would ever be used.
#define DT_INST_XXX(inst) DT_XXX(DT_DRV_INST(inst))
Glad to offer the commit/review cycles it takes to get this ready for <zephyr/drivers/video.h>
or <zephyr/devicetree.h>
.
include/zephyr/drivers/video.h
Outdated
#define _DT_INST_PORT_BY_ID(n, pid) \ | ||
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(n, ports)), (DT_CHILD(DT_INST_CHILD(n, ports), port_##pid)), (DT_INST_CHILD(n, port_##pid))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an ongoing discussion: #58007
But the status quo seems still be on having Z_
for internal macros for now:
zephyr/include/zephyr/sys/util_internal.h
Line 28 in 124aae3
#define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm missing something here, why not use this pattern? Or remove the underscore if users should be using this macro directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use this pattern directly if we are sure that the target port has an ID, e.g. port_0, port_1, etc. It will not work in case we have only 1 port with no ID. I will remove the underscore as this macro can be used both internally and publicly.
I tried to summarize my feedback into something like this, which I hope still matches what you had in mind: /* Handle the variability of "ports{port@0{}};" vs "port{};" while going down */
#define DT_INST_PORT_BY_ID(inst, pid) \
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, ports)), \
(DT_CHILD(DT_INST_CHILD(inst, ports), port_##pid)), \
(DT_INST_CHILD(inst, port)))
/* Handle the variability of "endpoint@0{};" vs "endpoint{};" while going down */
#define DT_INST_ENDPOINT_BY_ID(inst, pid, eid) \
COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint)), \
(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint)), \
(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint_##eid)))
/* Handle the variability of "ports{port@0{}};" vs "port{};" while going up */
#define DT_ENDPOINT_PARENT_DEVICE(node) \
COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(DT_GPARENT(node), port)), \
(DT_GPARENT(node)), (DT_PARENT(DT_GPARENT(node))))
/* Handle the "remote-endpoint-label" */
#define DEVICE_DT_GET_REMOTE_DEVICE(node) \
DEVICE_DT_GET(DT_ENDPOINT_PARENT_DEVICE( \
DT_NODELABEL(DT_STRING_TOKEN(node, remote_endpoint_label)))) Feel free to cherry-pick from it or ignore it altogether. |
=> This does not work when there is no That's why I defined two macros so that it works for all cases.
Also note that the 1st macro is not only an intermediate / internal macro. It can be used by drivers as well if they know exactly that the target port has a pid. Same comment for the endpoint macros. |
I had no idea! This all makes sense then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good for me! Thank you for your explanations on this.
+1 assuming that:
- Indentation is tuned to get check_compliance.py happy
- Documentation is added (glad to contribute it, but I do not want to break your workflow)
- The naming matches what devicetree maintainers want
- Their introduction in
video.h
is ok as per devicetree maintainers
Should the devicetree
tag be added?
Relating to the remote endpoint and remote device macros:
=> You check whether or not we have a However, by moving the node exist check to the local endpoint of the remote device, this version is simpler / better than mine. Will change to this. Thanks ! |
This is to be discussed. Ideally, it should be in If we keep them only for video, it's ok for the 1st phase. But do you know if there are examples in Zephyr that subsystem can have their own DT macros ? or all DT macros must go to |
It looks like driver classes do have their own macros! In a subdirectory of For instance zephyr/include/zephyr/devicetree.h Lines 5146 to 5158 in 4bb9453
When the macros generate a struct specific to one subsystem (i.e. zephyr/include/zephyr/drivers/i2c.h Lines 92 to 94 in 4bb9453
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment- we need additional documentation on these macros before we can move forwards with this PR, I assume that will be added?
Yes, I will put documentation and other things as discussed in the next push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, thank you for this update
I still need to resolve @rruuaanng 's comments, will do soon :-). |
b37117f
to
4a12693
Compare
@rruuaanng : In fact, there was already a blank line at the end of the file in my local IDE but github does not show it. I tried to add one more to the files as your request but then check-compliance has failed as you can see in CI check:
So, I will let it as before then ? |
It seems that my comment is not so clear. If there is a blank line at the end of the file, you can ignore my comment. I just suggest that please forgive my unclear description. Edit Delete the extra blank line and keep only one blank line at the end of the file. I apologize again :( |
4a12693
to
9b4b9a7
Compare
@rruuaanng No problem :-). Done. |
Add port and endpoint DT macros to retrieve the node id of the interested port/endpoint from its id. Also, add helpers to retrieve the peer remote device node from its local endpoint interface. Signed-off-by: Phi Bang Nguyen <[email protected]> Co-developed-by: Josuah Demangeon <[email protected]>
Add tests for the new port / endpoint DT macros Signed-off-by: Josuah Demangeon <[email protected]> Signed-off-by: Phi Bang Nguyen <[email protected]>
Drop the driver-defined macros to use the endpoint DT helpers instead. Signed-off-by: Phi Bang Nguyen <[email protected]>
9b4b9a7
to
1ea737e
Compare
force-push to fix CI build issue due to #79482 (which take these macros inside it) get merged first |
@danieldegrasse Could you revisit ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@decsny could you take a look as well?
This PR adds some port / endpoint DT helpers for the video drivers or others (e.g. display) and some examples of their simple usage in video drivers. Two main macros helpers are
DT_INST_ENDPOINT_BY_ID(inst, pid, id)
: to get the (local) endpoint node id from a port id and an endpoint idDT_NODE_REMOTE_DEVICE(ep)
: to get the peer remote device node from the local endpoint nodeA typical usage would be parsing all endpoints in a loop, or automatically parsing all endpoints till the end.